package first.group.ssh.gui.util;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;


public class TabUtil {
    public interface CloseListener {
        void onClose();
    }
    
    public static void addTab(JTabbedPane pane, String title, Component component, CloseListener closeListener) {
        pane.addTab(title, component);
        
        var panel = new JPanel();
        panel.setOpaque(false);

        var titleLabel = new JLabel(title);
        panel.add(titleLabel);

        var close = new JButton("x");
        close.setForeground(Color.LIGHT_GRAY);
        close.setBorder(null);
        close.addActionListener(evt -> {
            closeListener.onClose();
        });
        panel.add(close);
        
        pane.setTabComponentAt(pane.getTabCount() - 1, panel);
    }
}
